gift = {"LIU":"apple","LI":"pear","WEN":"banana","LUO":"orange","WU":"peach"}
# 用字典存储参会者的姓名和礼物
swap = {}
# 存储交换后的结果
fly = list(gift.keys())
for p in fly:
    flag = 0 #看自己带来的礼物是否送出去了
    if p in gift:
        flag = 1
        mygift = gift.pop(p) #要是礼物没送出去，就丢掉礼物
    getgift = gift.popitem()#随机返回并移除一对数据
    swap[p] = getgift[1] #得到的礼物
    if flag:
        gift[p] = mygift

print(swap)#输出礼物分配情况